import React from 'react';
import {Button,Icon} from 'antd';

/*
*  操作按钮权限组件包装器
*/
let permissions = undefined;

const Auth = Component =>class AuthComponent extends React.Component {
    // 构造
    constructor(props) {
        super(props);
        const user = JSON.parse(localStorage.getItem('user'));
        permissions = user ? user.permission : [];
    }
    render() {
        if (permissions.includes(this.props.permission)) {
            return <Component  { ...this.props} />;
        } else {
            return null;
        }
    }
};

class A extends  React.Component{
    constructor(props) {
        super(props);
    }
    render(){
        return(
            <a {...this.props}></a>
        );
    }
}

export const AuthA = Auth(A);
export const AuthButton = Auth(Button);
export const AuthIcon = Auth(Icon);